package com.moss.cloud.plugins.biz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moss.cloud.common.base.utils.PageUtil;
import com.moss.cloud.common.core.exception.SystemErrorType;
import com.moss.cloud.common.core.utils.BooleanHandel;
import com.moss.cloud.common.core.utils.DateUtil;
import com.moss.cloud.plugins.api.contant.enums.FieldDataType;
import com.moss.cloud.plugins.api.contant.enums.SyncStatusEnum;
import com.moss.cloud.plugins.api.contant.enums.TypeMapping;
import com.moss.cloud.plugins.api.model.dto.CustomDataSource;
import com.moss.cloud.plugins.api.model.from.*;
import com.moss.cloud.plugins.api.model.param.ModelDesignParam;
import com.moss.cloud.plugins.api.model.param.ZipTemplateParam;
import com.moss.cloud.plugins.api.model.vo.ModelDesignVO;
import com.moss.cloud.plugins.api.model.vo.ModelFieldVO;
import com.moss.cloud.plugins.biz.mapper.ModelDesignMapper;
import com.moss.cloud.plugins.biz.model.CodeTemplate;
import com.moss.cloud.plugins.biz.model.DataSourceConf;
import com.moss.cloud.plugins.biz.model.ModelDesign;
import com.moss.cloud.plugins.biz.model.ModelField;
import com.moss.cloud.plugins.biz.service.ICodeTemplateService;
import com.moss.cloud.plugins.biz.service.IDataSourceConfService;
import com.moss.cloud.plugins.biz.service.IModelDesignService;
import com.moss.cloud.plugins.biz.service.IModelFieldService;
import com.moss.cloud.plugins.biz.utils.AutoGenerationCode;
import com.moss.cloud.plugins.biz.utils.SqlActuator;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 模型设计业务实现
 *
 * @author 瑾年
 * @date 2024年1月4日
 */
@Slf4j
@Service
public class ModelDesignServiceImpl extends ServiceImpl<ModelDesignMapper, ModelDesign> implements IModelDesignService {

    private final IModelFieldService modelFieldService;

    private final IDataSourceConfService dataSourceConfService;

    private final Configuration configuration;

    private final ICodeTemplateService codeTemplateService;

    public ModelDesignServiceImpl(IModelFieldService modelFieldService, IDataSourceConfService dataSourceConfService,
                                  Configuration configuration, ICodeTemplateService codeTemplateService) {
        this.modelFieldService = modelFieldService;
        this.dataSourceConfService = dataSourceConfService;
        this.configuration = configuration;
        this.codeTemplateService = codeTemplateService;
    }

    /**
     * 模型分页查询
     *
     * @param param
     * @return
     */
    @Override
    public IPage<ModelDesign> page(ModelDesignParam param) {
        Page<ModelDesign> page = PageUtil.createPage(param.getCurrent(), param.getSize());
        return this.page(page, new QueryWrapper<ModelDesign>().lambda()
                .like(StringUtils.isNotBlank(param.getModelName()), ModelDesign::getModelName, param.getModelName())
                .eq(Objects.nonNull(param.getSyncStatus()), ModelDesign::getSyncStatus, param.getSyncStatus()));
    }

    /**
     * 新增模型设计
     *
     * @param modelDesignFrom
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveModelDesign(ModelDesignFrom modelDesignFrom) {
        ModelDesign modelDesign = new ModelDesign();
        BeanUtils.copyProperties(modelDesignFrom, modelDesign);
        boolean saveFlag = this.save(modelDesign);
        List<ModelField> modelFields = this.modelFields(modelDesignFrom, modelDesign.getId());
        return saveFlag ? modelFieldService.saveBatch(modelFields) : Boolean.FALSE;
    }

    /**
     * 更新模型设计
     *
     * @param modelDesignFrom
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateModelDesign(ModelDesignFrom modelDesignFrom) {
        BooleanHandel.trueThrow(Objects.isNull(modelDesignFrom.getId())).throwMessage(SystemErrorType.PRIMARY_KEY);
        this.checkModelData(modelDesignFrom.getId());
        ModelDesign model = new ModelDesign();
        BeanUtils.copyProperties(modelDesignFrom, model);
        boolean updateFlag = this.updateById(model);
        boolean delFlag = updateFlag ? modelFieldService.remove(new QueryWrapper<ModelField>().lambda()
                .eq(ModelField::getModelId, modelDesignFrom.getId())) : Boolean.FALSE;
        List<ModelField> fields = this.modelFields(modelDesignFrom, modelDesignFrom.getId());
        return delFlag ? modelFieldService.saveBatch(fields) : Boolean.FALSE;
    }

    /**
     * 构建模型字段数据
     *
     * @param modelDesignFrom
     * @param modelId
     * @return
     */
    private List<ModelField> modelFields(ModelDesignFrom modelDesignFrom, Long modelId) {
        return CollectionUtils.isNotEmpty(modelDesignFrom.getModelFieldFroms()) ?
                modelDesignFrom.getModelFieldFroms().stream().map(item -> {
                    ModelField modelField = new ModelField();
                    BeanUtils.copyProperties(item, modelField);
                    modelField.setModelId(modelId);
                    return modelField;
                }).collect(Collectors.toList()) : Collections.emptyList();
    }

    /**
     * 删除模型
     *
     * @param baseFrom
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean removeModelDesign(BaseFrom baseFrom) {
        this.checkModelData(baseFrom.getId());
        boolean delFlag = this.removeById(baseFrom.getId());
        return delFlag ? modelFieldService.remove(new QueryWrapper<ModelField>().lambda()
                .eq(ModelField::getModelId, baseFrom.getId())) : Boolean.FALSE;
    }

    /**
     * 验证数据
     *
     * @param modelId
     */
    private void checkModelData(Long modelId) {
        ModelDesign modelDesign = this.getById(modelId);
        BooleanHandel.trueThrow(Objects.isNull(modelDesign)).throwMessage(SystemErrorType.DATE_EMPTY);
        List<ModelField> modelFields = modelFieldService.list(new QueryWrapper<ModelField>().lambda()
                .eq(ModelField::getModelId, modelId));
        BooleanHandel.trueThrow(CollectionUtils.isEmpty(modelFields)).throwMessage(SystemErrorType.DATE_EMPTY);
    }

    /**
     * 模型详情
     *
     * @param baseFrom
     * @return
     */
    @Override
    public ModelDesignVO modeDetail(BaseFrom baseFrom) {
        ModelDesign modelDesign = this.getById(baseFrom.getId());
        ModelDesignVO modelDesignVO = new ModelDesignVO();
        BeanUtils.copyProperties(modelDesign, modelDesignVO);
        List<ModelField> modelFields = modelFieldService.list(new QueryWrapper<ModelField>().lambda()
                .eq(ModelField::getModelId, baseFrom.getId()).orderByAsc(ModelField::getOrderNum));
        List<ModelFieldVO> modelFieldVOS = CollectionUtils.isNotEmpty(modelFields) ? modelFields.stream().map(item -> {
            ModelFieldVO modelFieldVO = new ModelFieldVO();
            BeanUtils.copyProperties(item, modelFieldVO);
            return modelFieldVO;
        }).collect(Collectors.toList()) : Collections.emptyList();
        modelDesignVO.setModelFields(modelFieldVOS);
        return modelDesignVO;
    }

    /**
     * 获取SQL脚本
     *
     * @param baseFrom
     * @return
     */
    @Override
    public String getSqlScript(BaseFrom baseFrom) {
        ModelDesignVO modelDesignVO = this.modeDetail(baseFrom);
        StringBuffer sb = new StringBuffer();
        String buildSql = "CREATE TABLE IF NOT EXISTS " + modelDesignVO.getModelName() + "(";
        sb.append(buildSql);
        BooleanHandel.trueThrow(CollectionUtils.isEmpty(modelDesignVO.getModelFields())).throwMessage(SystemErrorType.DATE_EMPTY);
        modelDesignVO.getModelFields().forEach(item -> {
            sb.append(item.getField()).append(" ").append(item.getDataType());
            BooleanHandel.isTrue(item.getDataType().equals(FieldDataType.VARCHAR.getCode())).trueHandle(() ->
                    sb.append("(").append(item.getMaxLength()).append(")"));
            BooleanHandel.isTrue(item.getPrimaryKey()).trueHandle(() -> sb.append(" AUTO_INCREMENT "));
            BooleanHandel.isTrue(item.getDataType().equals(FieldDataType.DECIMAL.getCode())).trueHandle(() ->
                    sb.append("(").append(item.getMaxLength()).append(",").append(item.getReserve()).append(")"));
            BooleanHandel.isTrue(item.getNonEmpty()).trueHandle(() -> sb.append(" NOT NULL "));
            BooleanHandel.isTrue(item.getField().equals(FieldDataType.CREATE_TIME.getCode())).trueHandle(() ->
                    sb.append(" DEFAULT CURRENT_TIMESTAMP "));
            BooleanHandel.isTrue(item.getField().equals(FieldDataType.UPDATE_TIME.getCode())).trueHandle(() ->
                    sb.append(" DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP "));
            BooleanHandel.isTrue(item.getField().equals(FieldDataType.DELETED.getCode())).trueHandle(() ->
                    sb.append(" DEFAULT '0' "));
            sb.append(" COMMENT ").append("'").append(item.getFieldComment()).append("'").append(",");
        });
        sb.append("PRIMARY KEY (`id`))");
        sb.append(" ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT=").append("'").append(modelDesignVO.getModelComment()).append("';");
        return sb.toString();
    }

    /**
     * 同步数据源
     *
     * @param baseFrom
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean syncDataSource(BaseFrom baseFrom) {
        String createSql = this.getSqlScript(baseFrom);
        ModelDesign modelDesign = this.getById(baseFrom);
        BooleanHandel.trueThrow(SyncStatusEnum.SYNC.getCode().equals(modelDesign.getSyncStatus())).throwMessage(SystemErrorType.SYNC);
        DataSourceConf conf = this.checkDataSource(modelDesign.getDataSourceId());
        CustomDataSource customDataSource = CustomDataSource.builder().url(conf.getFullConnection())
                .userName(conf.getDatabaseUserName()).password(conf.getDatabasePassword()).build();
        int result = SqlActuator.createTable(customDataSource, createSql);
        modelDesign.setSyncStatus(SyncStatusEnum.SYNC.getCode());
        return result == 0 ? this.updateById(modelDesign) : Boolean.FALSE;
    }

    /**
     * 撤回同步
     *
     * @param baseFrom
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean recallSync(BaseFrom baseFrom) {
        ModelDesign modelDesign = this.getById(baseFrom.getId());
        BooleanHandel.trueThrow(Objects.isNull(modelDesign)).throwMessage(SystemErrorType.DATE_EMPTY);
        BooleanHandel.trueThrow(SyncStatusEnum.NO_SYNC.getCode().equals(modelDesign.getSyncStatus())).throwMessage(SystemErrorType.NO_SYNC);
        DataSourceConf dataSourceConf = this.checkDataSource(modelDesign.getDataSourceId());
        CustomDataSource customDataSource = CustomDataSource.builder().url(dataSourceConf.getFullConnection())
                .userName(dataSourceConf.getDatabaseUserName()).password(dataSourceConf.getDatabasePassword()).build();
        modelDesign.setSyncStatus(SyncStatusEnum.NO_SYNC.getCode());
        boolean flag = this.updateById(modelDesign);
        String sql = "DROP TABLE " + modelDesign.getModelName();
        return flag ? SqlActuator.executeRemove(customDataSource, sql) : Boolean.FALSE;
    }

    /**
     * 验证数据源是否存在
     *
     * @param dataSourceId
     * @return
     */
    private DataSourceConf checkDataSource(Long dataSourceId) {
        DataSourceConf dataSourceConf = dataSourceConfService.getById(dataSourceId);
        BooleanHandel.trueThrow(Objects.isNull(dataSourceConf)).throwMessage(SystemErrorType.DATE_EMPTY);
        return dataSourceConf;
    }

    /**
     * 生成代码
     *
     * @param generationCodeFrom
     * @param response
     * @return
     */
    @Override
    @SneakyThrows
    public void generateCode(HttpServletResponse response, GenerationCodeFrom generationCodeFrom) {
        this.generationCodeFrom(generationCodeFrom);
        Map<String, Object> map = new HashMap<>();
        map.put("model", generationCodeFrom);
        List<CodeTemplate> templates = codeTemplateService.codeTemplateList(Arrays.asList(1, 2));
        BooleanHandel.trueThrow(CollectionUtils.isEmpty(templates)).throwMessage(SystemErrorType.DATE_EMPTY);
        List<ZipTemplateParam> params = this.zipTemplateParam(templates, map, generationCodeFrom.getClassName(), generationCodeFrom.getModelName(), "");
        this.response(response, params, "code");
    }

    /**
     * 构建模板参数
     *
     * @param generationCodeFrom
     */
    private void generationCodeFrom(GenerationCodeFrom generationCodeFrom) {
        BaseFrom baseFrom = new BaseFrom();
        baseFrom.setId(generationCodeFrom.getId());
        ModelDesignVO modelDesignVO = this.modeDetail(baseFrom);
        generationCodeFrom.setClassName(AutoGenerationCode.toCamelCase(modelDesignVO.getModelName()));
        generationCodeFrom.setModelName(AutoGenerationCode.toJavaField(modelDesignVO.getModelName()));
        generationCodeFrom.setModelComment(modelDesignVO.getModelComment());
        generationCodeFrom.setCreatedDate(DateUtil.getNow(DateUtil.YMD));
        BooleanHandel.trueThrow(CollectionUtils.isEmpty(modelDesignVO.getModelFields())).throwMessage(SystemErrorType.DATE_EMPTY);
        modelDesignVO.getModelFields().removeIf(ModelFieldVO::getIsDefault);
        List<GenerationCodeFieldsFrom> generationCodeFieldsFroms = modelDesignVO.getModelFields().stream().map(item -> {
            GenerationCodeFieldsFrom generationCodeFieldsFrom = new GenerationCodeFieldsFrom();
            BeanUtils.copyProperties(item, generationCodeFieldsFrom);
            generationCodeFieldsFrom.setDataType(TypeMapping.getJavaType(item.getDataType()));
            generationCodeFieldsFrom.setField(AutoGenerationCode.toJavaField(item.getField()));
            return generationCodeFieldsFrom;
        }).collect(Collectors.toList());
        generationCodeFrom.setModelFieldFroms(generationCodeFieldsFroms);
    }

    /**
     * 读取模板
     *
     * @param templateContent
     * @param data
     * @return
     * @throws IOException
     * @throws TemplateException
     */
    private String renderTemplate(String templateContent, Map<String, Object> data) throws IOException, TemplateException {
        Template freemarkerTemplate = new Template("template", new StringReader(templateContent), configuration);
        StringWriter writer = new StringWriter();
        freemarkerTemplate.process(data, writer);
        return writer.toString();
    }

    /**
     * 获取模板压缩文件
     *
     * @param templates
     * @param map
     * @param className
     * @return
     */
    private List<ZipTemplateParam> zipTemplateParam(List<CodeTemplate> templates, Map<String, Object> map, String className, String modelName, String shortName) {
        List<ZipTemplateParam> params = new ArrayList<>();
        templates.forEach(item -> {
            String temp = null;
            try {
                temp = this.renderTemplate(item.getTemplateContent(), map);
            } catch (Exception e) {
                e.printStackTrace();
            }
            ZipTemplateParam param = new ZipTemplateParam();
            param.setTemplateContent(temp);
            BooleanHandel.isTrue(item.getTemplateName().startsWith("entity")).trueHandle(() -> param.setTemplateName("/biz/model/" + className + ".java"));
            BooleanHandel.isTrue(item.getTemplateName().startsWith("form")).trueHandle(() -> param.setTemplateName("/api/model/from/" + className + "From.java"));
            BooleanHandel.isTrue(item.getTemplateName().startsWith("param")).trueHandle(() -> param.setTemplateName("/api/model/param/" + className + "Param.java"));
            BooleanHandel.isTrue(item.getTemplateName().startsWith("mapper")).trueHandle(() -> param.setTemplateName("/biz/mapper/" + className + "Mapper.java"));
            BooleanHandel.isTrue(item.getTemplateName().startsWith("service.java")).trueHandle(() -> param.setTemplateName("/biz/service/" + "I" + className + "Service.java"));
            BooleanHandel.isTrue(item.getTemplateName().startsWith("serviceImpl")).trueHandle(() -> param.setTemplateName("/biz/service/impl/" + className + "ServiceImpl.java"));
            BooleanHandel.isTrue(item.getTemplateName().startsWith("controller")).trueHandle(() -> param.setTemplateName("/biz/controller/" + className + "Controller.java"));
            BooleanHandel.isTrue(item.getTemplateType().equals(2)).trueHandle(() -> {
                BooleanHandel.isTrue(item.getTemplateName().startsWith("api")).trueHandle(() -> param.setTemplateName("/vue/" + modelName + ".ts"));
                BooleanHandel.isTrue(item.getTemplateName().startsWith("columns")).trueHandle(() -> param.setTemplateName("/vue/columns.ts"));
                BooleanHandel.isTrue(item.getTemplateName().startsWith("list")).trueHandle(() -> param.setTemplateName("/vue/" + modelName + ".vue"));
            });
            BooleanHandel.isTrue(item.getTemplateType().equals(3)).trueHandle(() -> this.createProjectFiles(item, param, className, modelName, shortName));
            params.add(param);
        });
        return params;
    }

    /**
     * 标准项目模板生成
     *
     * @param response
     * @param projectCodeFrom
     */
    public void genProject(HttpServletResponse response, ProjectCodeFrom projectCodeFrom) {
        projectCodeFrom.setCreatedDate(DateUtil.getNow(DateUtil.YMD));
        Map<String, Object> map = new HashMap<>();
        map.put("projectModel", projectCodeFrom);
        List<CodeTemplate> templates = codeTemplateService.codeTemplateList(Collections.singletonList(3));
        this.handleTemplates(projectCodeFrom, templates);
        BooleanHandel.trueThrow(CollectionUtils.isEmpty(templates)).throwMessage(SystemErrorType.DATE_EMPTY);
        List<ZipTemplateParam> params = this.zipTemplateParam(templates, map, projectCodeFrom.getServerName(), projectCodeFrom.getPackageName(), projectCodeFrom.getShortName());
        this.response(response, params, projectCodeFrom.getServerName());
    }

    /**
     * 根据开启条件处理模板数据
     *
     * @param projectCodeFrom
     * @param templates
     * @return
     */
    private List<CodeTemplate> handleTemplates(ProjectCodeFrom projectCodeFrom, List<CodeTemplate> templates) {
        BooleanHandel.isTrue(!projectCodeFrom.getEnableComponent().contains("userChangeEvent")).trueHandle(() -> {
            templates.removeIf(x -> x.getTemplateName().startsWith("UserCreateMessage"));
            templates.removeIf(x -> x.getTemplateName().startsWith("UserRemoveMessage"));
            templates.removeIf(x -> x.getTemplateName().startsWith("UserUpdateMessage"));
        });
        BooleanHandel.isTrue(!projectCodeFrom.getEnableComponent().contains("userAccountLock")).trueHandle(() ->
                templates.removeIf(x -> x.getTemplateName().startsWith("UserLockMessage")));
        BooleanHandel.isTrue(!projectCodeFrom.getEnableComponent().contains("tenantInfoUpd")).trueHandle(() ->
                templates.removeIf(x -> x.getTemplateName().startsWith("TenantInfoMessage")));
        BooleanHandel.isTrue(!projectCodeFrom.getEnableComponent().contains("tenantStatus")).trueHandle(() ->
                templates.removeIf(x -> x.getTemplateName().startsWith("TenantStatus")));
        return templates;
    }

    /**
     * 文件流返回处理
     *
     * @param response
     * @param params
     */
    @SneakyThrows
    private void response(HttpServletResponse response, List<ZipTemplateParam> params, String fileName) {
        ByteArrayOutputStream out = AutoGenerationCode.createZipFile(params);
        response.setContentType("application/zip");
        response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".zip");
        try (ServletOutputStream outputStream = response.getOutputStream()) {
            out.writeTo(outputStream);
            out.flush();
        }
    }

    /**
     * 创建项目文件
     *
     * @param template
     * @param param
     * @param projectName
     * @param packageName
     */
    private void createProjectFiles(CodeTemplate template, ZipTemplateParam param, String projectName, String packageName, String shortName) {
        //创建项目文件夹
        String projectFolder = "/" + projectName + "/";
        String biz = projectFolder + projectName + "-biz/";
        String api = projectFolder + projectName + "-api/";
        String bizFolder = biz + "src/main/java/" + packageName.replace(".", "/") + "/" + shortName + "/biz/";
        String apiFolder = api + "src/main/java/" + packageName.replace(".", "/") + "/" + shortName + "/api/";
        String assemblyFolder = biz + "src/main/assembly/";
        String resourcesFolder = biz + "src/main/resources/";
        BooleanHandel.isTrue(template.getTemplateName().startsWith("Application")).trueHandle(() -> param.setTemplateName(bizFolder +
                "Application.java"));
        BooleanHandel.isTrue(template.getTemplateName().startsWith("pom")).trueHandle(() -> param.setTemplateName(projectFolder +
                "pom.xml"));
        BooleanHandel.isTrue(template.getTemplateName().startsWith("bootstrap")).trueHandle(() -> param.setTemplateName(resourcesFolder +
                "bootstrap.yml"));
        BooleanHandel.isTrue(template.getTemplateName().startsWith("assembly-linux")).trueHandle(() -> param.setTemplateName(assemblyFolder +
                "assembly-linux.xml"));
        BooleanHandel.isTrue(template.getTemplateName().startsWith("bizPom")).trueHandle(() -> param.setTemplateName(biz +
                "pom.xml"));
        BooleanHandel.isTrue(template.getTemplateName().startsWith("logback")).trueHandle(() -> param.setTemplateName(resourcesFolder +
                "logback.xml"));
        BooleanHandel.isTrue(template.getTemplateName().startsWith("servseName-dev")).trueHandle(() -> param.setTemplateName(resourcesFolder +
                projectName + "-dev.yml"));
        BooleanHandel.isTrue(template.getTemplateName().startsWith("apiPom")).trueHandle(() -> param.setTemplateName(api +
                "pom.xml"));
        BooleanHandel.isTrue(template.getTemplateName().startsWith("seizeSeat")).trueHandle(() -> param.setTemplateName(apiFolder +
                "seizeSeat.txt"));
        BooleanHandel.isTrue(template.getTemplateName().startsWith("UserCreateMessage")).trueHandle(() -> param.setTemplateName(bizFolder +
                "message/" + "UserCreateMessageListener.java"));
        BooleanHandel.isTrue(template.getTemplateName().startsWith("UserRemoveMessage")).trueHandle(() -> param.setTemplateName(bizFolder +
                "message/" + "UserRemoveMessageListener.java"));
        BooleanHandel.isTrue(template.getTemplateName().startsWith("UserUpdateMessage")).trueHandle(() -> param.setTemplateName(bizFolder +
                "message/" + "UserUpdateMessageListener.java"));
        BooleanHandel.isTrue(template.getTemplateName().startsWith("UserLockMessage")).trueHandle(() -> param.setTemplateName(bizFolder +
                "message/" + "UserLockMessageListener.java"));
        BooleanHandel.isTrue(template.getTemplateName().startsWith("TenantInfoMessage")).trueHandle(() -> param.setTemplateName(bizFolder +
                "message/" + "TenantInfoMessageListener.java"));
        BooleanHandel.isTrue(template.getTemplateName().startsWith("TenantStatus")).trueHandle(() -> param.setTemplateName(bizFolder +
                "message/" + "TenantStatusMessageListener.java"));
    }
}
